package de.koller.renderEngine.physics;

import de.koller.oceanFramework.util.MOut;

public class PyIO {

	private static final int CONTR_CUBE = 0;
	private static final int CONTR_FRAME = 1;
	
	private final String file;
	private final int steps;

	public PyIO( String file, int steps ) {
		this.file = file;
		this.steps = steps;
	}
	
	public void write( PhysicsRoot proot ) {
		MOut o = new MOut( file );
		
		for( int i = 0; i < steps; i++ ) {
			proot.update();
			o.writeInt( CONTR_FRAME );
			
			for( CubeData c : proot )
				writeCube( o, c );
			
			System.out.println( i + "/" + steps );
		}
			
		o.close();	
	}
	
	public void writeCube( MOut o, CubeData c ) {
		o.writeInt( CONTR_CUBE );
		o.writeFloat( c.x, c.y, c.w, c.h, c.r );
	}
	
}
